package com.song.pattern.singleton;

public class Singleton {
	/*持有私有静态实例,防止被引用,此处赋值为null*/
	private static Singleton instance = new Singleton();
	
	/*私有构造方法,防止被实例化*/
	private Singleton(){}
	
	/*静态工程方法,创建实力*/
	public static Singleton getInstance(){
//		if(instance == null){
//			instance = new Singleton();
//		}
		return instance;
	}
	
	/*如果该对象呗用于序列化,可以保证对象在序列化前后保持一致*/
	public Object readResolve(){
		return instance;
	}
}
